﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Content/Master.Master" Inherits="System.Web.Mvc.ViewPage<SCS.Core.ViewModels.MenuViewModels>" %>
<%@ Import Namespace="SCS.Core" %>
<%@ Import Namespace="SCS.Core.Models" %>
<%@ Import Namespace="SCS.Core.ViewModels" %>
<%@ Import Namespace="SCS.Core.Controllers" %>
<%@ Import Namespace="SCSService" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Danh sách Menu
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<script type="text/javascript" src="/ThemeExtends/AdminSkin/js/jquery.flot.js"></script>
<script type="text/javascript" src="/ThemeExtends/AdminSkin/js/jquery.flot.stack.js"></script>	
<script type="text/javascript">
   
    function SaveStatus(dropDownList, id) {
        var selectedReport = dropDownList.options[dropDownList.selectedIndex];
        var selects = selectedReport.value;
        actionChangeStatus(selects, id);
    }
    function actionChangeStatus(values, id) {
        var url = '<%=Url.Action("ChangeStatusMenu","AdvantageSetting")%>' + '/' + id + '/' + values;
        $.getJSON(url, function (outStr) {
            $('#statusID' + id).val(outStr);
        });
    }    
</script> 
<% using (Html.BeginForm("ListMenu", "AdvantageSetting", FormMethod.Post, new { id = "sendFileForm", enctype = "multipart/form-data" }))
   {%>
    <div class="clear"></div>
    <div class="column full">
    <div class="box ">
		<h2 class="box-header">Danh sách Menu </h2>
		<div class="box-content">

                    <div id="grid">
        
		                 <div style="margin: 5px; float:right;">  <%= Html.ActionLink("Thêm mới", "AddMenu", null, new { @Class = "button themed" })%></div>
				    						               
				               <table class="display" id="tabledata">
                                <thead>
					                <tr>
                                        <th>
                                          
								                ID
                                        </th>				               
						                <th>
							                
								                Tên Menu
						                </th>
						
						                <th>
							               
								                Mô tả
						                </th>											                
                                        
                                        <th>
                                                Đường dẫn
                                        </th>                                       
                                        
                                        <th>
                                              
								                trạng thái
                                        </th>

                                        <th>
                                           
								                Sắp xếp
                                        </th>

                                        <th>Hành động</th>
					                </tr>
                                </thead>
                                <% if (Model.MenuList.Count() == 0)
                                   { %>
			                        <tbody>
                                        <tr>
                                            <td colspan="8">
                                             Không tìm thấy
                                            </td>
                                        </tr>
                                    </tbody>
		                        <% } else { %>
                                <tbody>
					                <% foreach (var item in Model.MenuList) { %>
				    
						                <tr>						                
                                            <td>
                                               <%= item.MenuId %>
                                            </td>

                                            <td>
                                               <%= item.MenuName %>
                                            </td>

                                            <td>
                                               <%= item.MenuText %>
                                            </td>

                                            <td>
                                               <%= item.MenuUrl %>
                                            </td>

                                            <td>
                                                <%
                                                    int newStatus=0;
                                                    if (item.MenuStatus == 0)
                                                    {
                                                        newStatus=1;
                                                    }
                                                    else if (item.MenuStatus == 1)
                                                    {
                                                        newStatus=0;
                                                    }
                                                    
                                                %>
                                                <%
                                                    List<SelectListItem> statusDrop = new List<SelectListItem>();
                                                    statusDrop.AddRange(new SelectListItem[] { 
                                                    new SelectListItem{Selected=newStatus==1?true:false, Text = "Kích hoạt", Value = "1" },
                                                    new SelectListItem{Selected=newStatus==1?true:false, Text = "Không kích hoạt", Value = "0" }
                                                });
                                                %>
                                               
                                               <%= Html.DropDownList("statusID" + item.MenuId, statusDrop, new { onchange = "SaveStatus(this," + item.MenuId + ")" })%>
                                            </td>

							                <td>
                                               <%= item.SortOrder %>
                                            </td>

                                            <td>   
								               <%-- <%= Html.ActionLink("Cập nhật", "EditMenu", new { id = item.MenuId })%>	--%>	
                                                <span class="button white"> <%= Html.ActionLink(" ", "EditMenu", new { id = item.MenuId }, new { @class = "icon_single edit", style = "color:#f7a468;" })%></span>	<!--cap nhat-->						                
                                                <%
                                                    string returnUrl = Request.Url.ToString();
                                                 %>
                                               <%-- <%= Html.ActionLink("Xóa", "DeleteMenu", new { id = item.MenuId, returnUrl = returnUrl }, new { onclick = "return confirm('Are you sure delete ?');" })%>--%>
                                                 <span class="button white"><%= Html.ActionLink(" ", "DeleteMenu", new { id = item.MenuId, returnUrl = returnUrl }, new { @class = "icon_single cancel", style = "color:#cc0000;", onclick = "return confirm('Bạn thực sự muốn xóa?');" })%></span>
                                            </td>
						                </tr>
				    
					                <% } %>
					            </tbody>
                                <% } %>
				                </table>
			                <!-- data -->
                                <% if (Model.MenuList.Count() > 0)
                                   { %>
			                       <% Html.RenderPartial("~/Views/Commont/Paging.ascx"); %>
		                        <% } %>
		                
	                </div>  <!-- grid -->	
                
               
	    </div>
	</div>
    <div class="clear"></div>
    </div>    
<% } %>

</asp:Content>
